<?php
namespace app\index\controller;

use think\Controller;
use think\Db;

/**
 * Class Index
 * @package app\index\controller bootstrap-table 表格插件
 */
class Index extends Controller
{
    public function index()
    {
        return $this->fetch();
    }
    public function test()
    {
        $data = Db::name('user')->limit(10)->select();
        return $data;
    }
    public function page()
    {
        $pageNumber = $this->request->get('pageNumber');
        $pageSize = $this->request->get('pageSize');
        $name = $this->request->get('name');
        $mobile = $this->request->get('mobile');

        if($name != NULL){
            $data = Db::name('user')->where('name', 'LIKE', '%'.$name.'%')->limit($pageNumber, $pageSize)->select();
            $count = Db::name('user')->where('name', 'LIKE', '%'.$name.'%')->count();
            $get = 1;
        }elseif($mobile != NULL){
            $data = Db::name('user')->where('mobile', 'LIKE', '%'.$mobile.'%')->limit($pageNumber, $pageSize)->select();
            $count = Db::name('user')->where('mobile', 'LIKE', '%'.$mobile.'%')->count();
            $get = 2;
        }else{
            $data = Db::name('user')->limit($pageNumber, $pageSize)->select();
            $count = Db::name('user')->count();
            $get = 3;
        }
        return [
            'total'      =>         $count,
            'rows'       =>         $data,
            'get'=>$get
        ];
    }
    public function weapp(){
        return json_encode([
            '20181212'	=>	'双十二',
            '20181224'	=>	'平安夜',
            '20181225'	=>	'圣诞节',
            '20181226'	=>	'生日'
        ]);
    }
}
